from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(60*2+1):       
            dot1=Dot([-500,5*(i-60),0]).set_opacity(0.5)
            dot2=Dot([500,5*(i-60),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(100*2+1):        
            dot3=Dot([(i-100)*5,-300,0]).set_opacity(0.5)
            dot4=Dot([(i-100)*5,300,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        self.play(self.camera.frame.animate.scale(1).move_to([0,0,0]))
        
        #题目出现
      
        text2 = Tex(r"\text{(2016年)设函数}$f\left( x\right) $\text{满足方程}$y''+2y'+ky=0( 0 <k < 1) $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,25,0])
        text20 = Tex(r"\text{(1)证明:反常积分}$\int _{0}^{+\infty }y\left( x\right) dx$\text{收敛}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,20,0])
        text200 = Tex(r"\text{(2)若}$y\left( 0\right) =1,y'\left( 0\right) =1,$\text{求}$\int _{0}^{+\infty }y\left( x\right) dx$\text{的值}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,15,0])
        





        
        self.play(Create(text2),Create(text20),Create(text200))
        
          #分析文本
        #text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-38,12.5,0])
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)
        #题目向上移动
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=21,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([12.5,25,0])
        self.play(Create(rectangle))
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=20,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([5,20,0])
        self.play(
            ReplacementTransform(rectangle,rectangle1)
        )
        self.wait(0.2)
        arrow = Arrow(start=[0,17,0],end=[-10,7,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow))
        text3 = Tex(r"\text{判敛法则}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,4,0])
        self.play(Create(text3))
        text4 = Tex(r"\text{(定性分析)}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,0,0])
        self.play(Create(text4))
        arrow1 = Arrow(start=[-10,-3,0],end=[-10,-13,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow1))
        text5 = Tex(r"\text{比较判别法以及极限形式}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,-16,0])
        self.play(Create(text5))
        arrow2 = Arrow(start=[10,17,0],end=[20,7,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow2))
        text6 = Tex(r"\text{求出积分值}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,4,0])
        self.play(Create(text6))
        text7 = Tex(r"\text{(定量分析)}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,0,0])
        self.play(Create(text7))
        arrow3 = Arrow(start=[20,-3,0],end=[20,-13,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow3))
        text8 = Tex(r"\text{计算不定积分的能力}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-16,0])
        self.play(Create(text8))

        text9 = Tex(r"\text{先得到}$f\left( x\right) $",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(8.0).move_to([5,0,0])
        self.play(
            ReplacementTransform(arrow,text9),
            ReplacementTransform(arrow1,text9),
            ReplacementTransform(arrow2,text9),
            ReplacementTransform(arrow3,text9),
            ReplacementTransform(text6,text9),
            ReplacementTransform(text5,text9),
            ReplacementTransform(text4,text9),
            ReplacementTransform(text7,text9),
            ReplacementTransform(text8,text9),
            ReplacementTransform(text3,text9),
        
        )
        self.wait(0.2)
        rectangle2=Rectangle(color=BLUE,fill_opacity=0.0,width=21,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle2.move_to([12.5,25,0])
        self.play(
            ReplacementTransform(text9,rectangle2)
           
        
        )
        self.wait(0.2)
        text10 = Tex(r"\text{二阶常系数齐次线性}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([35,20,0])
        self.play(Create(text10))
        text11 = Tex(r"$y''+py'+qy=0$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,10,0])
        self.play(Create(text11))
        text12 = Tex(r"$\lambda ^{2}+px+q=0$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,5,0])
        self.play(Create(text12))
        text13 = Tex(r"$\left\{\begin{matrix}\Delta  >0 \Rightarrow & \lambda _{1}\neq \lambda _{2} & \Rightarrow\\\Delta  =0 \Rightarrow & \lambda _{1}=\lambda _{2} & \Rightarrow\\\Delta  <0\Rightarrow & \lambda _{1,2}=\alpha +\beta i &\Rightarrow\end{matrix}\right.$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,-10,0])
        self.play(Create(text13))
        text14 = Tex(r"$y=c_{1}e^{-\lambda _{1}x}+c_{2}e^{-\lambda _{2}x}$",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([10,-7,0])
        text15 = Tex(r"$y=\left( c_{1}+c_{2}x\right) e^{\lambda _{1}x}$",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([10,-10,0])
        text16 = Tex(r"$y=e^{\alpha x}\left[ c_{1}\cos \beta x+c_{2}\sin \beta x\right] $",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([10,-13,0])
        self.play(Create(text14),Create(text15),Create(text16))

        



        text110 = Tex(r"$\lambda ^{2}+2\lambda +k=0$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,5,0])
        self.play(
            ReplacementTransform(text10,text110)
           
        
        )
        self.wait(0.2)
        text17 = Tex(r"$\Delta =4-4k >0$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,0,0])
        self.play(Create(text17))
         #半透明矩阵扩展
        rectangle4=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([10,-7,0])
        self.play(
            rectangle4.animate.stretch(25.0,dim=0)
        )
        arrow3 = Arrow(start=[0,5,0],end=[10,5,0],color=BLUE
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow3))
        text18 = Tex(r"$\lambda _{1}+\lambda _{2}=-2$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,7,0])
        text19 = Tex(r"$\lambda _{1}\lambda _{2}=k >0$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,3,0])
        self.play(Create(text18),Create(text19))

        text20 = Tex(r"$\Rightarrow \lambda _{1},\lambda _{2} <0$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([37,5,0])
        self.play(Create(text20))
        text21 = Tex(r"$ \lambda _{1},\lambda _{2} <0$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([15,10,0])
        text22 = Tex(r"$y=c_{1}e^{\lambda _{1}x}+c_{2}e^{\lambda _{2}x}$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-15,10,0])
        self.play(
            ReplacementTransform(text20,text21)
           ,ReplacementTransform(rectangle4,text22)
            ,FadeOut(text19,text18,arrow3,text17,text16,text15,text110,text14,text13,text12,text11)
        )
        rectangle5=Rectangle(color=BLUE,fill_opacity=0.0,width=21,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle5.move_to([-15,10,0])
        self.play(Create(rectangle5))

        arrow4 = Arrow(start=[-15,7,0],end=[-15,-7,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow4))
        text23 = Tex(r"$\int _{0}^{+\infty }y\left( x\right) dx=\left( \dfrac{c_{1}}{\lambda _{1}}e^{-\lambda _{1}x}+\dfrac{c_{2}}{\lambda _{2}}e^{-\lambda _{2}x}\right) _{0}^{+\infty }$",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-15,-15,0])
        self.play(Create(text23))
        rectangle6=Rectangle(color=BLUE,fill_opacity=0.0,width=11,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle6.move_to([15,10,0])
        rectangle7=Rectangle(color=BLUE,fill_opacity=0.0,width=11,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle7.move_to([15,10,0])
        self.play(Create(rectangle6),Create(rectangle7))
        text24 = Tex(r"$=\left( 0+0\right) -\left( \dfrac{c_{1}}{\lambda _{1}}+\dfrac{c_{2}}{\lambda _{2}}\right) $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text23,RIGHT,buff=1)
        self.play(
            ReplacementTransform(rectangle7,text24)
           
        )
        self.wait(0.2)
        text25 = Tex(r"$=-\dfrac{c_{1}}{\lambda _{1}}-\dfrac{c_{2}}{\lambda 2}$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text23,RIGHT,buff=1)

        self.play(
            ReplacementTransform(text24,text25)
           
        )
        self.wait(0.2)
        text26 = Tex(r"$\Rightarrow \int _{0}^{+\infty }y\left( x\right) dx$\text{收敛}",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text25,RIGHT,buff=2)
        self.play(Create(text26))
        self.wait(0.2)
        self.wait()  
